﻿using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.Commands.DepartmentCommands
{

    public class DepartmentTreeCreateHandler : IRequestHandler<DepartmentTreeCreateCommand, Result>
    {
        private readonly IBaseRepository<DepartTree> treebaseRepository;

        public DepartmentTreeCreateHandler(IBaseRepository<DepartTree> treebaseRepository)
        {
            this.treebaseRepository = treebaseRepository;
        }
        /// <summary>
        /// 部门级联的添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(DepartmentTreeCreateCommand request, CancellationToken cancellationToken)
        {
            var result= new Result() { Code=(int)CodeEnum.add};
            var list = treebaseRepository.Add(new DepartTree { DepartTreeName = request.DepartTreeName, Pid = request.Pid });
            result.Code = list;
            return result;
        }
    }
}
